package com.ruoyi.project.system.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.DepartmentList;
import com.ruoyi.project.system.service.IDepartmentListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 科室接口控制器
 */
@RestController
@RequestMapping("/system/department")
public class DepartmentController extends BaseController {

    @Autowired
    private IDepartmentListService departmentListService;

    /**
     * 前端请求地址：/dev-api/system/department/sub-list?degree=xxx
     * 根据一级科室名称查询二级科室列表
     */
    @Anonymous
    @GetMapping("/sub-list")
    public AjaxResult getSubList(@RequestParam("degree") String degree) {
        // 调用服务层查询数据
        List<DepartmentList> subDepartments = departmentListService.getSubDepartmentsByDegree(degree);
        // 按若依标准格式返回（code=200，data=列表数据）
        return AjaxResult.success(subDepartments);
    }
}